﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _111
{
    public class Node<T>
    {
        public Node<T> next { get; set; }
        public T data { get; set; }
        public Node(T d)
        {   data = d;
            next = null;
        }
    }
    public class List<T>
    {
        public Node<T> head;
        public Node<T> tail;
        public List()
        {
            head = tail = null;
        }
        public  Node<T> Head { get { return head; } }
        public void Add(T d) 
        {
            Node<T> n = new Node<T>(d);
            if(tail == null) 
            {
                head = tail = n;
            }
            else
            {
             tail.next = n;
             tail = n;
            }
        }
        public void ForEach(Action<T> action)
        {
            Node<T> cur = head;
            while(cur != null) 
            {
                action(cur.data);
                cur = cur.next;
            }
        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> l = new List<int>();
            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            Console.WriteLine("打印链表元素: ");
            l.ForEach(x => Console.WriteLine(x));
            int max = int.MinValue;
            l.ForEach(x => { if (x > max) max = x; });
            Console.WriteLine("最大值: " + max);
            int min = int.MaxValue;
            l.ForEach(x => { if(x<min) min = x; });
            Console.WriteLine("最小值: " + min);
            int sum = 0;
            l.ForEach(x => { sum += x; });
            Console.WriteLine("和为：" + sum);
        }
    }
}
